from functools import wraps

from django.http import JsonResponse
from django.shortcuts import render

from App_SearchNovel.Tools import isLogin, ParseBook


def forlogin(url = None):
    def loginfunc(func):
        @wraps(func)
        def todo(request):
            if isLogin(request):
                return func(request)
            else:
                if url is None:
                    return JsonResponse({"status": False})
                else:
                    return render(request, url)
        return todo
    return loginfunc

def homedata(request,data = None):
    return {"data": ParseBook(data),"userid":request.session.get("userid",None)}